package com.lc.afbx.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lc.afbx.R;
import com.lc.afbx.fragment.LiPeiApplyFragment;
import com.lc.afbx.fragment.LiPeiSerachFragment;

/**
 * Created by Administrator on 2016/5/19.
 */
public class InsuranceSearchActivity extends BaseActivity implements View.OnClickListener {


    private TextView liPei_search_tv;
    private TextView liPei_apply_tv;

    private LiPeiSerachFragment liPeiSerachFragment;
    private LiPeiApplyFragment liPeiApplyFragment;

    private Fragment[] fragments;
    private int prePosition;
    private int index;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shouye_lipeichaxun);

        liPei_apply_tv = (TextView) findViewById(R.id.liPei_apply_tv);
        liPei_search_tv = (TextView) findViewById(R.id.liPei_search_tv);

        findViewById(R.id.back).setOnClickListener(this);
        findViewById(R.id.liPei_apply_tv).setOnClickListener(this);
        findViewById(R.id.liPei_search_tv).setOnClickListener(this);

        liPeiApplyFragment = new LiPeiApplyFragment();
        liPeiSerachFragment = new LiPeiSerachFragment();

        fragments = new Fragment[]{liPeiSerachFragment, liPeiApplyFragment };

        getSupportFragmentManager().beginTransaction().add(R.id.fragment_container_rl, liPeiSerachFragment)
                .show(liPeiSerachFragment).commit();


    }

    @Override
    public void onClick(View view) {

        FragmentTransaction trx = getSupportFragmentManager().beginTransaction();

        switch (view.getId()) {

            case R.id.back:

                finish();

                break;

            case R.id.liPei_search_tv:

                index = 0;

                liPei_apply_tv.setTextColor(ContextCompat.getColor(context, R.color.textColorHui));
                liPei_search_tv.setTextColor(Color.parseColor("#0095d2"));

                if (index != prePosition) {

                    trx.hide(fragments[prePosition]);

                    if (!fragments[index].isAdded()) {

                        trx.add(R.id.fragment_container_rl, fragments[index]);
                    }

                    trx.show(fragments[index]).commit();

                    prePosition = index;

                }

                break;

            case R.id.liPei_apply_tv:

                index = 1;

                liPei_apply_tv.setTextColor(Color.parseColor("#0095d2"));
                liPei_search_tv.setTextColor(ContextCompat.getColor(context, R.color.textColorHui));

                if (index != prePosition) {

                    trx.hide(fragments[prePosition]);

                    if (!fragments[index].isAdded()) {

                        trx.add(R.id.fragment_container_rl, fragments[index]);
                    }

                    trx.show(fragments[index]).commit();

                    prePosition = index;

                }

                break;



        }

    }


}
